package com.jp.knowledge.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.model.attention.AttentionSelectGroupModel;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;

import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/3/29.
 */

public class AttentionGroupSelectAdapter extends RecycleVAdapter<AttentionSelectGroupModel.ListBean> implements View.OnClickListener {

    public AttentionGroupSelectAdapter(Context context, List<AttentionSelectGroupModel.ListBean> infos) {
        super(context, infos);
    }

    @Override
    public int getLayoutId(int position) {
        return R.layout.item_attention_group_select;
    }

    @Override
    public void onBind(RecycleVHolder holder, int position) {
        holder.setTextView(R.id.item_title, getData(position).getTitle());
        TextView attentionBtn = holder.get(R.id.attention_btn);
        View loadingView = holder.get(R.id.loading);
        if(getData(position).getIsJoin() == 1) {
            loadingView.setVisibility(View.GONE);
            attentionBtn.setVisibility(View.VISIBLE);
            attentionBtn.setText("已监控");
            attentionBtn.setTextColor(mContext.getResources().getColor(R.color.font_gray_think));
            attentionBtn.setBackground(mContext.getResources().getDrawable(R.drawable.search_btn_gray));
        } else if(getData(position).getIsJoin() == 0){
            loadingView.setVisibility(View.GONE);
            attentionBtn.setVisibility(View.VISIBLE);
            attentionBtn.setText("监控");
            attentionBtn.setTextColor(mContext.getResources().getColor(R.color.theme_color));
            attentionBtn.setBackground(mContext.getResources().getDrawable(R.drawable.search_btn_blue));
        } else if(getData(position).getIsJoin() == -1){     // 加载中
            attentionBtn.setVisibility(View.INVISIBLE);
            loadingView.setVisibility(View.VISIBLE);
        } else/* if(getData(position).getIsJoin() == -2)*/{     // 加载失败
            loadingView.setVisibility(View.GONE);
            attentionBtn.setVisibility(View.GONE);
        }
        attentionBtn.setTag(position);
        attentionBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(this.listener != null) {
            listener.onAtteneionBtnClick((int) v.getTag());
        }
    }

    private OnAttentionBtnClickListener listener;
    public void setOnAttentionBtnClickListener(OnAttentionBtnClickListener listener){
        this.listener = listener;
    }
    public interface OnAttentionBtnClickListener{
        void onAtteneionBtnClick(int position);
    }
}
